package com.zkingsoft.interceptors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.zkingsoft.plugin.util.SessionUtils;

public class CheckAdminiLoginInterceptor implements HandlerInterceptor {

	Logger log = Logger.getLogger(this.getClass());

	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
	}

	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
	}

	/**
	 * 检查管理员是否登陆
	 */
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {

		String requestUrl = request.getRequestURI();
		log.info(requestUrl);
		// 如果访问特殊的路径需要验证登录权限
		if (requestUrl.indexOf("/common/redirect/satellite") != -1 || requestUrl.indexOf("/manage/") != -1
				|| requestUrl.indexOf("/monitor/") != -1) {
//			if (SessionUtils.getSessionObject("roleId") == null || "".equals(SessionUtils.getSessionObject("roleId"))) {
//				response.sendRedirect(request.getContextPath() + "/common/redirect/login");
//				return false;
//			} else {
				return true;
//			} 
		} else {
			return true;
		}
	}

}
